package org.zhxy.core.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.zhxy.entity.personnel.UserTeacher;
import org.zhxy.entity.system.User;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Update("update pe_user set status = #{status} where id = #{userId}")
    void updateStatusForUser(@Param("userId") String userId,@Param("status") String status);


    @Select("<script> SELECT u.*,t.*, " +
            "( SELECT GROUP_CONCAT(d.`label`) FROM sc_teacher_department td, sc_department d WHERE t.`id` = td.`teacher_id` AND td.`department_id` = d.`id` AND td.`status` = '1' ) AS departmentNames, " +
            "( SELECT GROUP_CONCAT(td.`department_id`) FROM sc_teacher_department td WHERE t.`id` = td.`teacher_id` AND td.`status` = '1') AS departmentIds,  " +
            "( SELECT GROUP_CONCAT(r.`name`) FROM pe_role r, pe_user_role ur WHERE t.`id` = u.`id` AND u.`id` = ur.`user_id` AND ur.`role_id` = r.`id`) AS roleNames, " +
            "( SELECT GROUP_CONCAT(ur.`role_id`) FROM pe_user_role ur WHERE t.`id` = u.`id` AND u.`id` = ur.`user_id` ) AS roleIds, " +
            "( SELECT tg.`general_status` FROM sc_teacher_general tg WHERE t.id = tg.user_id ) AS generalStatus,  " +
            "( SELECT tr.`resignation_status` FROM sc_teacher_resignation tr WHERE t.`id` = tr.`user_id`) AS resignationStatus  " +
            "FROM pe_user u, sc_teacher t " +
            "WHERE u.`id` = t.`id` " +
            "AND u.id= #{userId} </script>")
    UserTeacher searchTeacherBySelf(String userId);
}
